package controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.BasicConfigurator;

import commons.Constants;

import DB.Connection.DBConnectionPool;
import DB.FreeBaseImport.FreeBaseImport;

import view.General.LegenDateGUI;

/**
 * The main class of the project
 */
public class LegenDateManager {

	private static final Log logger = LogFactory.getLog(LegenDateManager.class);

	public static void main(String[] args) {

		logger.info("*** Starting LegenDate application! ***");

		BasicConfigurator.configure();

		logger.info("Starting LegenDate GUI...");
		Thread guiThread = new Thread(LegenDateGUI.get());
		guiThread.start();
		try {
			guiThread.join();
		} catch (Exception e) {
			logger.error("GUI Exception!", e);
		}

		DBConnectionPool.closeAllConnections();
		System.exit(0);
	}

	public static void updateDB(String url, String user, String password) {
		Constants.setDBUrl(url);
		Constants.setDBUserName(user);
		Constants.setDBPassword(password);

		FreeBaseImport fbi = new FreeBaseImport(false);
		Thread fbiThread = new Thread(fbi);
		fbiThread.start();
	}
}
